-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Runner that watches for Kubernetes APIs #4036
Conversation
@@ -293,9 +293,9 @@ func PodSecurityContext(cluster *v1beta1.PostgresCluster) *corev1.PodSecurityCon | |||
// - https://cloud.redhat.com/blog/a-guide-to-openshift-and-uids | |||
// - https://docs.k8s.io/tasks/configure-pod-container/security-context/ | |||
// - https://docs.openshift.com/container-platform/4.8/authentication/managing-security-context-constraints.html | |||
if cluster.Spec.OpenShift == nil || !*cluster.Spec.OpenShift { | |||
podSecurityContext.FSGroup = initialize.Int64(26) | |||
if !initialize.FromPointer(cluster.Spec.OpenShift) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, OK, had to read the func / re-read the word "initialize" to get it: we give the value of the pointer or the null value of the type if the pointer is null.
So: Spec.OpenShift: true => true ; and false/nil => false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this call doesn't read well. A function that returns zero when a pointer is nil sounds intuitive, but I dunno in practice. Other functions in this package act on the pointers they're passed, so that combo is confusing, too.
K8s has a not-versioned pile of util
with a ptr Deref(p *T, default T) T
. That doesn't read much better to me.
runner.have.Version = version.Info{ | ||
Major: "1", Minor: "2", GitVersion: "asdf", | ||
} | ||
assert.Equal(t, "asdf", VersionString(NewAPIContext(ctx, runner))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL String()
only returns the GitVersion, cf. https://github.com/kubernetes/apimachinery/blob/a8f449e276fe566efddb149992049c78f0088492/pkg/version/types.go#L35-L37
We should probably extend our discovery runner the next time we want to use the discovery client.
This adds an
internal/kubernetes
package with types and functions for interrogating the Kubernetes API version and the APIs it has installed.kubernetes.APIs
is an interface for some read-only methods of k8s.io/…/sets.Set.kubernetes.APISet
implementes theAPIs
interface using amap
.kubernetes.DiscoveryRunner
implements theAPIs
interface by periodically calling the Kubernetes API.main()
configures a DiscoveryRunner and adds it to the Manager and its Context so that the rest of our code can use it with these new functions:kubernetes.Has(Context, API) bool
kubernetes.IsOpenShift(Context) bool
kubernetes.VersionString(Context) string
Checklist:
Type of Changes:
What is the current behavior (link to any open issues here)?
What is the new behavior (if this is a feature change)?
Other Information:
This is similar to #3973, but has grown to replace all our runtime use of the upstream discovery client.